--平畴理风
local pingchoulifeng = fk.CreateSkill {
    name = "mcdh_pingchoulifeng",
    tags = {Skill.Switch}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

pingchoulifeng:addEffect(fk.CardUseFinished,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not  player:hasSkill(self)  or player:usedSkillTimes(pingchoulifeng.name,Player.HistoryTurn) >= 1 then return false end
        if player:getSwitchSkillState(pingchoulifeng.name, false) == fk.SwitchYang   and not player:isNude() then
            local cards = Card:getIdList(data.card)
            return #cards > 0 and table.every(cards, function(id) return room:getCardArea(id) == Card.Processing end)
                    and #data.card:getDefaultTarget(player,{bypass_times=true}) ~= 0

        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local color
        if data.card.color == Card.NoColor then return false end
        if data.card.color == Card.Red then
            color = "heart,diamond"
        else
            color = "spade,club"
        end
        local  card =room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|"..color.."|.|.|"..data.card:getTypeString() , "#pingchoulifeng-discard:::"..data.card:getColorString()..":"..data.card:getTypeString())
        if #card > 0  then
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = Card:getIdList(data.card)
        room:askToUseVirtualCard(player,{name = data.card.name,subcards=cards,skill_name = self.name,prompt="#pingchoulifeng-use:::"..data.card.name,extra_data={bypass_times=true,extraUse=true},cancelable=false})
    end
})

pingchoulifeng:addEffect(fk.TurnEnd,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not  player:hasSkill(self)  or player:usedSkillTimes(pingchoulifeng.name,Player.HistoryTurn) >= 1 then return false end
        if player:getSwitchSkillState(pingchoulifeng.name, false) == fk.SwitchYin  then
            local  events =room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
                return e.data.who == player
            end, Player.HistoryTurn)
            return #events > 0
        end

    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targetPlayers = room:askToChoosePlayers(player, {
            targets = room:getAlivePlayers(),
            min_num = 1,
            max_num = 1,
            prompt = "#wuyuanfujie-choose",
            skill_name = self.name,
            cancelable = true
          })
        if #targetPlayers > 0 then
            self.cost_data = targetPlayers[1]
            return true
        end

    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = self.cost_data
        room:damage({to = to,from = player,damage = 1,skillName =pingchoulifeng.name})
    end
})

Fk:loadTranslationTable {
    ["mcdh_pingchoulifeng"] = "平畴理风",
    [":mcdh_pingchoulifeng"] = "转换技。每回合限一次。①当一名角色使用基本牌或普通锦囊牌结算后，你可以弃置一张与此牌类别和颜色均相同的牌，并使用此牌（无次数限制）。②你体力值变化过的回合结束时，你可以对一名角色造成1点伤害。",
    ["#pingchoulifeng-discard"] = "平畴理风：弃置一张 %arg %arg2",
    ["#pingchoulifeng-use"] = "平畴理风：使用此 %arg",
    ["#wuyuanfujie-choose"] = "平畴理风：对一名角色造成1点伤害",
}

return pingchoulifeng